//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;
using OpenLS.Core.Serialization;
using System.ComponentModel;

namespace OpenLS.Drawing
{
    public class DefaultShapeDefinition : ViewModelBase, IOfficeXmlSerializableAs, IShape
    {
        private TextBodyProperties bodyPr;
        private TextListStyle lstStyle;
        private ShapeProperties spPr;
        private ShapeStyle style;

        public ShapeProperties ShapeProperties
        {
            get
            {
                if (spPr == null)
                    spPr = new ShapeProperties();
                return spPr;
            }
            set { spPr = value;
                notifyPropertyChanged("ShapeProperties"); }
        }

        public TextBodyProperties TextBodyProperties
        {
            get
            {
                if (bodyPr == null)
                    bodyPr = new TextBodyProperties();
                return bodyPr;
            }
            set { bodyPr = value;
                notifyPropertyChanged("TextBodyProperties"); }
        }

        public TextListStyle TextListStyle
        {
            get
            {
                if (lstStyle == null)
                    lstStyle = new TextListStyle();
                return lstStyle;
            }
            set { lstStyle = value;
                notifyPropertyChanged("TextListStyle"); }
        }

        public ShapeStyle ShapeStyle
        {
            get { return style; }
            set { style = value;
                notifyPropertyChanged("ShapeStyle"); }
        }

        #region IOfficeXmlSerializableAs Members

        void IOfficeXmlSerializableAs.ReadXmlAs(string name, ReadContext context)
        {
            using (var c = context.Read(name))
            {
                ShapeProperties = c.ReadElement<ShapeProperties>();
                TextBodyProperties = c.ReadElement<TextBodyProperties>();
                TextListStyle = c.ReadOptionalElementAs<TextListStyle>("lstStyle");
                ShapeStyle = c.ReadOptionalElement<ShapeStyle>("style");
                c.WarnIf("ext");
            }
        }

        void IOfficeXmlSerializableAs.WriteXmlAs(string name, WriteContext context)
        {
            using (WriteContext c = context.Write(name))
            {
                c.WriteElement(ShapeProperties);
                c.WriteElement(TextBodyProperties);
                c.WriteOptionalElementAs(TextListStyle, "lstStyle"); //\\ need switch?
                c.WriteOptionalElement(ShapeStyle);
                c.WarnIf("ext");
            }
        }

        #endregion

    }
}